!

(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Navigation Api tutorial

Description: In this tutorial we will explain how to work with ros navigation api

Keywords: ric_nav, ric_navigation, ric nav, ric navigation

Tutorial Level: INTERMEDIATE

Setup

This line includes the action specification for move_base which is a ROS action that exposes a high level interface to the navigation stack. Essentially, the move_base action accepts goals from clients and attempts to move the robot to the specified position/orientation in the world. For a detailed discussion of ROS actions see the

   1 import rospy
   2 from actionlib import SimpleActionClient, GoalStatus
   3 from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal

Constructs an action client

This line constructs an action client that we'll use to communicate with the action named "move_base" that adheres to the MoveBaseAction interface. Also we starting up a node call ‘simple navigation goals’, and in the end for this piece for code we wait for the action server to start.

   1 rospy.init_node("simple_navigation_goals")
   2 move_base_client = SimpleActionClient('move_base', MoveBaseAction)
   3 rospy.loginfo('Connecting to server')
   4 move_base_client.wait_for_server()

Constructing goals

Here we create a goal to send to move_base using the move_base_msgs::MoveBaseGoal message type which is included automatically with the MoveBaseAction.h header. We'll just tell the base to move 1 meter forward in the "komodo_1/base_link" coordinate frame. The call to move_base_client.send_goal will actually push the goal out over the wire to the move_base node for processing.

   1 goal = MoveBaseGoal()
   2 goal.target_pose.header.frame_id = 'komodo_1/base_link'
   3 goal.target_pose.header.stamp = rospy.Time.now()
   4 goal.target_pose.pose.position.x = -1.0
   5 goal.target_pose.pose.orientation.w = 1.0
   6 
   7 rospy.loginfo('Sending goal')
   8 move_base_client.send_goal(goal)

The only thing left to do now is to wait for the goal to finish using the move_base_client.wait_for_result call which will block until the move_base action is done processing the goal we sent it. After it finishes, we can check if the goal succeded or failed and output a message to the user accordingly.

   1 move_base_client.wait_for_result()
   2 
   3 if move_base_client.get_state() == GoalStatus.SUCCEEDED:
   4     rospy.loginfo('Hooray, the base moved 1 meter forward')
   5 else:
   6     rospy.loginfo('The base failed to move forward 1 meter for some reason')

Wiki: ric_navigation/Navigation api (last edited 2015-11-22 08:16:14 by tomwiss1231)